﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>安卓消息推送</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<style text="text/css">
#mytable {
width: 600px;
padding: 0;
margin: 0;
}

th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA no-repeat;
}


th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff no-repeat;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
}

th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa no-repeat;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #797268;
}
</style>
</head>
<body>
	<center>
	  <div id="addDiv">
		  <form id="addForm" method="post" action="add.php">
		  <fieldset style="width:400,height:200     " >
		  <input type="hidden" name="dopost" value="add"/>
			<table>
				<tr>
					<td ><label>主题:</label></td><td><input name="title" id="title" required/></td>
				</tr>
				<tr>
					<td><label>游戏名：</label></td><td><input name="gameName" id="gameName" required/></td>
				</tr>
				<tr>
					<td><label>内容：</label></td><td><textarea  rows="5"cols="30" name="content" id="content" required></textarea></td>
				</tr>
				<tr >
				<td colspan="2" align="right"><input type="submit" value="添加"><td>
				</tr>
			</table>
			</fieldset>
		  </form>
	  </div>
	  
	  <br/><br/><br/>  <hr/>  <br/><br/><br/>
	  <div>
	  <!--搜索查询-->
	  <div>
			<form class="searchDiv" method="get" action="view.php">
			
				<input name="key" placeholder="搜索"/>
				<input type="submit" value="搜索">
			</form>
	  </div>
	 <br/>
	  <!--  显示列表块显示-->
	  <div id="showDiv">		
			<table id="mytable" cellspacing="0" border="1" >
				<thead>
					<tr>
					  <th  scope="col">编号</th>
					  <th>主题</th>
					  <th>游戏名</th>
					  <th>内容</th>
					  <th>时间</th>
					  <th>操作</th>
					</tr>   
				</thead>
				<tbody>
<?php		
	/*分页数据
	* $now_page 当前页
	* $page_size 每页显示条数
	* $start 查询起始
	*/
	$now_page = empty($_GET['p'])? 1 : $_GET['p'];//当前页面
	//echo$now_page;
	$page_size = 5;//页面记录条数	
	$start = ($now_page-1) * $page_size;
	//$total_result=0;
	
	//数据库连接查询操作
	$conn =mysql_connect('localhost','root','');
	mysql_select_db('info_push');
	mysql_query("set names utf8");				
	
	
	$query='select * from push limit1';
	//获取页面总条数	
	$total_result=mysql_fetch_assoc( mysql_query("select count(id) as count from push") );	
	//关键字搜索SQL与总条数
	if( !empty($_GET['key']))
	{
		$key = ($_GET['key']);
		$res_query = "select count(id) as count from push 	where title like '%{$key}%' or content like '%{$key}'";
		$total_result=mysql_fetch_assoc( mysql_query($res_query));	
		
		$query = "select id,title,gameName,content,time from push 
				where title like '%{$key}%' or content like '%{$key}'
				limit {$start},{$page_size}";		
	}else{//查询SQL与总条数
		$query = "select id,title,gameName,content,time from push limit {$start},{$page_size}";
	}
	$result = mysql_query($query,$conn) or die('select failed:'.mysql_error());
	
	//结果集显示
	if(mysql_num_rows($result))
	{
		$content='';
		while($row = mysql_fetch_assoc($result)){
			$content.=<<<eof
<tr >
	<th class="resId">{$row['id']}</th>
	<th class="resTitle">{$row['title']}</th>
	<th class="resGName">{$row['gameName']}</th>
	<th class="resCtent">{$row['content']}</th>
	<th class="resTime">{$row['time']}</th>
	<th>
		<a class="modify" style="cursor:pointer" >修改|</a>
		<a class="del" style="cursor:pointer" >删除</a>
	</th>
</tr>
eof;
//	<th class="modify" style="cursor:pointer" >修改</th>
		}
	}else{
		$content.=<<<eof
<tr >
	<th colspan="6" align="center"> 没有一条记录</th>
</tr>
eof;
	}
	echo $content;
	
?>									
				</tbody>
			</table>
<?php
	require "Page.class.php";
	//分页显示
	$params = array(
				'total_rows'=>$total_result['count'], #(必须)
				'method'    =>'php', #(必须)
				'parameter' =>'view.php',  #(必须)
				'now_page'  =>$now_page,  #(必须)
				'list_rows' =>$page_size, #(可选) 默认为15
	);
	

	$page = new Page($params);
	if(!empty($_GET['key']))
		$page->setParamArr( array('key'=>$_GET['key']) );//设置url date参数
	echo  $page->show(1);
?>		
	  </div>
	  
	  
	  <hr/><br/><br/>
	  <!--  编辑块显示-->
	  <div class="modifyDiv">
	    <form id="editForm" method="post" action="add.php">
		<fieldset>
		<input type="hidden" name="dopost" value="edit">		
		 <table id="editTb">
				<tr>
					<td></td><td><input type="hidden" name="id" id="editId" readonly="readonly" required/></input>
				</tr>
				<tr>
					<td><label>主题:</label></td><td><input name="title" id="editTitle" required/></td>
				</tr>
				<tr>
					<td><label>游戏名：</label></td><td><input name="gameName" id="editGName" required/></td>
				</tr>
				<tr>
					<td><label>内容：</label></td><td><textarea  rows="5"cols="30" name="content" id="editCtent" required></textarea></td>
				</tr>
				<tr >
				<td colspan="2" align="right"><input type="submit" class="btnAdd" type="button" value="添加"><td>
				</tr>
			</table>
		</fieldset>
		</form>
	  </div>
	  <!--  删除块显示-->
	  <div class="delDiv">
			<form id="delForm" method="post" action="add.php">
			<fieldset>
			<input type="hidden" name="dopost" value="delete">		
			 <table id="editTb">
					<tr>
						<td></td><td><input type="hidden" name="id" id="delId" readonly="readonly" required/></input>
					</tr>
					<tr>
						<td><label>主题:</label></td><td><input name="title" id="delTitle" readonly="readonly"required/></td>
					</tr>
					<tr>
						<td><label>游戏名：</label></td><td><input name="gameName" id="delGName" readonly="readonly" required/></td>
					</tr>
					<tr>
						<td><label>内容：</label></td><td><textarea  rows="5"cols="30" name="content" id="delCtent" readonly="readonly" required></textarea></td>
					</tr>
					<tr >
					<td colspan="2" align="right"><input type="submit" class="btnAdd" type="button" value="确认删除"><td>
					</tr>
				</table>
			</fieldset>
		</form>		
	  </div>
	</center>
	
	
	<script type="text/javascript" src="./jquery.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
		  $(".modifyDiv").hide();
		  $(".delDiv").hide();
		  $(".modify").click(function(i){
						
			var id=$(this).parent().parent().children(".resId").text();			
			var title=$(this).parent().parent().children(".resTitle").text();			
			var gameName=$(this).parent().parent().children(".resGName").text();			
			var content=$(this).parent().parent().children(".resCtent").text();			
			
			document.getElementById("editId").value=id;
			document.getElementById("editTitle").value=title;
			document.getElementById("editGName").value=gameName;
			document.getElementById("editCtent").value=content;	
			
			$(".modifyDiv").fadeIn(1500);
			$(".delDiv").fadeOut();
						
		  });		  
		  
		  $(".del").click(function(i){
		    $(".delDiv").fadeIn(1500);
			$(".modifyDiv").fadeOut();
						
			var id=$(this).parent().parent().children(".resId").text();			
			var title=$(this).parent().parent().children(".resTitle").text();			
			var gameName=$(this).parent().parent().children(".resGName").text();			
			var content=$(this).parent().parent().children(".resCtent").text();			
		
			document.getElementById("delId").value=id;
			document.getElementById("delTitle").value=title;
			document.getElementById("delGName").value=gameName;
			document.getElementById("delCtent").value=content;

		  });
		});
	</script>
</body>
</html>
